#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,p,ans[10]={0,1,6,66,1064,22680,602352,2129036};
signed main(){
	freopen("tree.in","r",stdin);
	freopen("tree.out","w",stdout);
	scanf("%lld%lld",&n,&p);
	printf("%lld",ans[n]%p);
	return 0;
}
